package com.app.teaware.util;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.schedulers.Schedulers;

public class ThreadUtils {

    //主线程做操作
    public static void doOnUIThread(UITask uiTask) {
        Observable.just(uiTask)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(uiTask1 -> uiTask1.doOnUI());

    }

    //io线程做操作
    public static void doOnThread(ThreadTask threadTask) {
        Observable.just(threadTask)
                .observeOn(Schedulers.io())
                .subscribe(threadTask1 -> threadTask1.doOnThread());
    }

    public interface ThreadTask {
        void doOnThread();
    }

    public interface UITask {
        void doOnUI();
    }
}